 $(document).ready(function(){
	 /*整个页面的右键菜单*/
	 $("#c_body").contextmenu(function(e){
			  var actives = $(".dir_file_active");
			  actives.each(function(index,item){
					$(item).removeClass("dir_file_active");
				});
			$(".file_menu").hide();
			$(".dir_menu").hide();
			var winWidth = $(document).width();
		
			var winHeight = $(document).height();
		
			var posX = e.pageX;
		
			var posY = e.pageY;
		
			var menuWidth = $(".contextmenu").width();
		
			var menuHeight = $(".contextmenu").height();
		
			var secMargin = 10;
		
			if(posX + menuWidth + secMargin >= winWidth
		
			&& posY + menuHeight + secMargin >= winHeight){
		
			  posLeft = posX - menuWidth - secMargin + "px";
		
			  posTop = posY - menuHeight - secMargin + "px";
		
			}
		
			else if(posX + menuWidth + secMargin >= winWidth){
		
			  posLeft = posX - menuWidth - secMargin + "px";
		
			  posTop = posY + secMargin + "px";
		
			}
		
			else if(posY + menuHeight + secMargin >= winHeight){
		
			  posLeft = posX + secMargin + "px";
		
			  posTop = posY - menuHeight - secMargin + "px";
		
			}
		
			else {
		
			  posLeft = posX + secMargin + "px";
		
			  posTop = posY + secMargin + "px";
		
			};
		
			$(".contextmenu").css({
		
			  "left": posLeft,
		
			  "top": posTop
		
			}).show();
			return false;
		
		  });
		  
	/*文件的右键菜单*/
	 $("#c_body .file").on("contextmenu",function(e){
			  var actives = $(".dir_file_active");
			  actives.each(function(index,item){
					$(item).removeClass("dir_file_active");
				});
			  $(this).addClass("dir_file_active");
			  $(".contextmenu").hide();
			  $(".dir_menu").hide();
			  var winWidth = $(".file").width();
				
			  var winHeight = $(".file").height();
				
			  var posX = e.pageX;
				
			  var posY = e.pageY;
				
			  var menuWidth = $(".file_menu").width();
				
			  var menuHeight = $(".file_menu").height();
				
			  var secMargin = 5;
				
			  var posLeft = (posX+secMargin) + "px";
			  var posTop = (posY+secMargin) + "px";
			  dirOrFileClick(this);
			  $(".file_menu").css({
				
				"left": posLeft,
				
				"top": posTop
				
			  }).show();
			  return false;
		  });
		  
	/* 文件夹右键列表 */
	$("#c_body .dir").on("contextmenu",function(e){
		console.log("文件夹右键菜单");
		  var actives = $(".dir_file_active");
		  actives.each(function(index,item){
				$(item).removeClass("dir_file_active");
			});
		  $(this).addClass("dir_file_active");
		  $(".file_menu").hide();
		  $(".contextmenu").hide();
		  var winWidth = $(".dir").width();
			
		  var winHeight = $(".dir").height();
			
		  var posX = e.pageX;
			
		  var posY = e.pageY;
			
		  var menuWidth = $(".dir_menu").width();
			
		  var menuHeight = $(".dir_menu").height();
			
		  var secMargin = 5;
			
		  var posLeft = (posX+secMargin) + "px";
		  var posTop = (posY+secMargin) + "px";
		  dirOrFileClick(this);
			
		  $(".dir_menu").css({
			
			"left": posLeft,
			
			"top": posTop
			
		  }).show();
		  return false;
	  });
	 /*实时刷新右键菜单*/
	 $("#c_body").on("mousemove",".file,.dir",function(){
		 $("#c_body .file").on("contextmenu",function(e){

			 var actives = $(".dir_file_active");
			 actives.each(function(index,item){
				 $(item).removeClass("dir_file_active");
			 });
			 $(this).addClass("dir_file_active");
			 $(".contextmenu").hide();
			 $(".dir_menu").hide();
			 var winWidth = $(".file").width();

			 var winHeight = $(".file").height();

			 var posX = e.pageX;

			 var posY = e.pageY;

			 var menuWidth = $(".file_menu").width();

			 var menuHeight = $(".file_menu").height();

			 var secMargin = 5;

			 var posLeft = (posX+secMargin) + "px";
			 var posTop = (posY+secMargin) + "px";
			 dirOrFileClick(this);
			 $(".file_menu").css({

				 "left": posLeft,

				 "top": posTop

			 }).show();
			 return false;
		 });
		 $("#c_body .dir").on("contextmenu","body",function(e){

			 var actives = $(".dir_file_active");
			 actives.each(function(index,item){
				 $(item).removeClass("dir_file_active");
			 });
			 $(this).addClass("dir_file_active");
			 $(".file_menu").hide();
			 $(".contextmenu").hide();
			 var winWidth = $(".dir").width();

			 var winHeight = $(".dir").height();

			 var posX = e.pageX;

			 var posY = e.pageY;

			 var menuWidth = $(".dir_menu").width();

			 var menuHeight = $(".dir_menu").height();

			 var secMargin = 5;

			 var posLeft = (posX+secMargin) + "px";
			 var posTop = (posY+secMargin) + "px";
			 dirOrFileClick(this);

			 $(".dir_menu").css({

				 "left": posLeft,

				 "top": posTop

			 }).show();
			 return false;
		 });
		 return false;
	 });
 });